/* SPDX-License-Identifier: GPL-2.0+ */
/*
 * Copyright (C) 2013 Gateworks Corporation
 */

splashpos=m,m
splashimage=CONFIG_SYS_LOAD_ADDR
usb_pgood_delay=2000
console=ttymxc1
bootdevs=usb mmc sata flash
hwconfig=_UNKNOWN_

disk=0
part=1

fdt_high=0xffffffff
fdt_addr=0x18000000
initrd_high=0xffffffff
fixfdt=fdt addr ${fdt_addr}
bootdir=boot
loadfdt=
	if ${fsload} ${fdt_addr} ${bootdir}/${fdt_file}; then
		echo Loaded DTB from ${bootdir}/${fdt_file};
		run fixfdt;
	elif ${fsload} ${fdt_addr} ${bootdir}/${fdt_file1}; then
		echo Loaded DTB from ${bootdir}/${fdt_file1};
		run fixfdt;
	elif ${fsload} ${fdt_addr} ${bootdir}/${fdt_file2}; then
		echo Loaded DTB from ${bootdir}/${fdt_file2};
		run fixfdt;
	fi

fs=ext4
script=6x_bootscript-ventana
loadscript=
	if ${fsload} ${loadaddr} ${bootdir}/${script}; then
		source ${loadaddr};
	fi

uimage=uImage
mmc_root=mmcblk0p1
mmc_boot=
	setenv fsload "${fs}load mmc ${disk}:${part}";
	mmc dev ${disk} && mmc rescan &&
	setenv dtype mmc; run loadscript;
	if ${fsload} ${loadaddr} ${bootdir}/${uimage}; then
		setenv bootargs console=${console},${baudrate}
			root=/dev/${mmc_root} rootfstype=${fs}
			rootwait rw ${video} ${extra};
		if run loadfdt; then
			bootm ${loadaddr} - ${fdt_addr};
		else
			bootm;
		fi;
	fi

sata_boot=
	setenv fsload "${fs}load sata ${disk}:${part}";
	sata init &&
	setenv dtype sata; run loadscript;
	if ${fsload} ${loadaddr} ${bootdir}/${uimage}; then
		setenv bootargs console=${console},${baudrate}
			root=/dev/sda1 rootfstype=${fs}
			rootwait rw ${video} ${extra};
		if run loadfdt; then
			bootm ${loadaddr} - ${fdt_addr};
		else
			bootm;
		fi;
	fi

usb_boot=
	setenv fsload "${fs}load usb ${disk}:${part}";
	usb start && usb dev ${disk} &&
	setenv dtype usb; run loadscript;
	if ${fsload} ${loadaddr} ${bootdir}/${uimage}; then
		setenv bootargs console=${console},${baudrate}
			root=/dev/sda1 rootfstype=${fs}
			rootwait rw ${video} ${extra};
		if run loadfdt; then
			bootm ${loadaddr} - ${fdt_addr};
		else
			bootm;
		fi;
	fi

#ifdef CONFIG_SPI_FLASH
image_os=ventana/openwrt-imx6-imx6q-gw5400-a-squashfs.bin
image_uboot=ventana/u-boot_spi.imx

spi_koffset=0x90000
spi_klen=0x200000

spi_updateuboot=echo Updating uboot from
	${serverip}:${image_uboot}...;
	tftpboot ${loadaddr} ${image_uboot} &&
	sf probe && sf erase 0 80000 &&
		sf write ${loadaddr} 400 ${filesize}
spi_update=echo Updating OS from ${serverip}:${image_os}
	to ${spi_koffset} ...;
	tftp ${loadaddr} ${image_os} &&
	sf probe &&
	sf update ${loadaddr} ${spi_koffset} ${filesize}

flash_boot=
	if sf probe &&
	sf read ${loadaddr} ${spi_koffset} ${spi_klen}; then
		setenv bootargs console=${console},${baudrate}
			root=/dev/mtdblock3
			rootfstype=squashfs,jffs2
			${video} ${extra};
		bootm;
	fi
#else
image_rootfs=openwrt-imx6-ventana-rootfs.ubi
nand_update=echo Updating NAND from ${serverip}:${image_rootfs}...;
	tftp ${loadaddr} ${image_rootfs} &&
	nand erase.part rootfs &&
	nand write ${loadaddr} rootfs ${filesize}

flash_boot=
	setenv fsload 'ubifsload';
	ubi part rootfs;
	if ubi check boot; then
		ubifsmount ubi0:boot;
		setenv root ubi0:rootfs ubi.mtd=2
			rootfstype=squashfs,ubifs;
		setenv bootdir;
	elif ubi check rootfs; then
		ubifsmount ubi0:rootfs;
		setenv root ubi0:rootfs ubi.mtd=2
			rootfstype=ubifs;
	fi;
	setenv dtype nand; run loadscript;
	if ${fsload} ${loadaddr} ${bootdir}/${uimage}; then
		setenv bootargs console=${console},${baudrate}
			root=${root} ${video} ${extra};
		if run loadfdt; then
			ubifsumount;
			bootm ${loadaddr} - ${fdt_addr};
		else
			ubifsumount; bootm;
		fi;
	fi
#endif
